'use strict';
import React from "react";
import {View, StyleSheet} from "react-native";
import BaseStore from "./BaseStore";
import {action, computed, observable, runInAction, toJS} from "mobx";

class TaskStore extends BaseStore {

    constructor(params) {
        super(params);
        this.taskList = {topic: "3d74c7bab87e46a7ad32f560df40fe3f",};
    }

    @observable taskList;

    @computed
    get getTaskList() {
        return toJS(this.taskList);
    }

    @action
    saveTask = async (key) => {
        const taskId = this.taskList[key];
        const data = {
            create_user: global.secretKey,
            task_id: taskId,
        };
        const dataSource = await this.postRequest(ServicesApi.TASK_DETAIL_SAVE,data);
        return dataSource;
    };

    @action
    requestTaskList = async () => {
        const dataSource = await this.postRequest(ServicesApi.TASK_LIST);
        runInAction(() => {
            if (dataSource.code === StatusCode.SUCCESS_CODE) {
                dataSource.data.map((item,i) => {
                    this.taskList[`${item.task_code}`] = item.task_id;
                });
                // console.log('this.taskList-------->',this.getTaskList);
            }
        });
        return dataSource
    };
}


export default TaskStore